// pages/knowledge/knowledge.js
Page({
  data: {
    activeTab: '0',
    articles: [
      {
        id: '1',
        title: '经期可以做的舒缓瑜伽',
        description: '几个简单动作，有效缓解腹部不适。',
        image: 'https://images.unsplash.com/photo-1544367567-0f2fcb009e0b?w=100&h=100&fit=crop',
        date: '2025-06-28',
        views: '2.3k',
        likes: '128'
      },
      {
        id: '2',
        title: '生理期吃什么？补铁食物清单',
        description: '菠菜、红肉、豆制品...这样吃恢复元气。',
        image: 'https://images.unsplash.com/photo-1506126613408-444548763556?w=100&h=100&fit=crop',
        date: '2025-07-05',
        views: '3.1k',
        likes: '215'
      },
      {
        id: '3',
        title: '改善经期失眠的5个小技巧',
        description: '从调整枕头到一杯热牛奶，帮你安然入睡。',
        image: 'https://images.unsplash.com/photo-1571019613454-1cb2f99b2d8e?w=100&h=100&fit=crop',
        date: '2025-07-10',
        views: '1.8k',
        likes: '156'
      },
      {
        id: '4',
        title: '月经期情绪波动怎么办？',
        description: '三分钟冥想练习，帮你稳定情绪，找回平静。',
        image: 'https://images.unsplash.com/photo-1493225457124-a3eb161ffa5f?w=100&h=100&fit=crop',
        date: '2025-07-12',
        views: '2.5k',
        likes: '189'
      }
    ]
  },

  onLoad: function() {
    // Additional initialization if needed
  },

  onTabsChange: function(e) {
    const { value } = e.detail;
    this.setData({ activeTab: value });
    
    // In a real app, you would fetch new articles for the selected tab
    this.fetchArticlesForTab(value);
  },

  fetchArticlesForTab: function(tabValue) {
    // Simulate API call with timeout
    wx.showLoading({
      title: '加载中...',
    });

    setTimeout(() => {
      // Keep the same articles for demonstration
      wx.hideLoading();
    }, 500);
  },

  onSearch: function() {
    wx.showToast({
      title: '搜索功能开发中',
      icon: 'none'
    });
  },

  // 隐藏功能：连续点击标题5次进入小游戏
  clickCount: 0,
  clickTimer: null,
  
  onTitleTap: function() {
    this.clickCount++;
    
    // 清除之前的定时器
    if (this.clickTimer) {
      clearTimeout(this.clickTimer);
    }
    
    // 如果在2秒内点击5次，进入游戏
    if (this.clickCount >= 5) {
      this.clickCount = 0;
      wx.navigateTo({
        url: '/pages/chicken_game/chicken_game'
      });
      return;
    }
    
    // 2秒后重置点击次数
    this.clickTimer = setTimeout(() => {
      this.clickCount = 0;
    }, 2000);
  },

  viewArticle: function(e) {
    const id = e.currentTarget.dataset.id;
    wx.showToast({
      title: `查看文章ID: ${id}`,
      icon: 'none'
    });
    
    // In a real app, navigate to article detail page
    // wx.navigateTo({
    //   url: `/pages/article-detail/article-detail?id=${id}`
    // });
  }
}); 